package com.glodon.paas.util;

import java.util.Random;
import java.util.UUID;

import org.apache.commons.codec.binary.Base64;


public class TokenUtil {
	private static Random random = new Random();
	private static int tokenSecretLengthBytes = 40;
	
	public static Random getRandom() {
		return random;
	}
	
	public static void setRandom(final Random rand) {
		random = rand;
	}
	
	public static int getTokenSecretLengthInBytes() {
		return tokenSecretLengthBytes;
	}
	
	public static void setTokenSecretLengthInBytes(final int len) {
		tokenSecretLengthBytes = len;
	}
	
	public static String newTokenValue() {
		return UUID.randomUUID().toString();
	}
	
	public static String newTokenSecret() {
		byte[] secretBytes = new byte[tokenSecretLengthBytes];
		random.nextBytes(secretBytes);
		return new String(Base64.encodeBase64(secretBytes));
	}
}
